package com.cn.algorithm.one.set;

import com.cn.algorithm.one.map.HashMap;
import com.cn.algorithm.one.map.Map;
import com.cn.algorithm.one.map.VisitMap;

public class HashSet<E> implements Set<E> {

    Map<E, Object> map = new HashMap<>();

    @Override
    public int size() {
        return map.size();
    }

    @Override
    public boolean isEmpty() {
        return map.isEmpty();
    }

    @Override
    public void clear() {
        map.clear();
    }

    @Override
    public void add(E element) {
        map.put(element, null);
    }

    @Override
    public void remove(E element) {
        map.remove(element);
    }

    @Override
    public boolean contains(E element) {
        return map.containsKey(element);
    }

    @Override
    public void traversal(VisitMap<E, Object> visit) {
        map.traversal(visit);
    }


    public static void main(String[] args) {
        Integer data[] = new Integer[]{
                // 7, 4
                // 7, 4, 9
                // 7, 4, 9, 5
                // 7, 4, 9, 2
                // 7, 4, 9, 2, 8
                7, 4, 8, 9, 10, 2, 3, 1
        };

        HashSet<Integer> map = new HashSet<>();
        for (int i = 0; i < data.length; i++) {
            map.add(data[i]);
        }
        System.out.println(map.size());
        System.out.println("----------------------------------");
        map.remove(1);
        System.out.println(map.contains(1));
        System.out.println(map.contains(3));
        System.out.println(map.size());

    }
}
